package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.domain.SpuDomain;
import com.ngc.mall.param.CategoryParam;
import com.ngc.mall.service.ICategoryService;
import com.ngc.mall.service.ISpuService;
import com.ngc.mall.vo.PagingVO;
import com.ngc.mall.vo.SpuVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/spu")
public class SpuController {
    @Resource
    private ISpuService iSpuService;

    @Resource
    private ICategoryService iCategoryService;


    @GetMapping("/detail/{id}")
    @ApiOperation("根据id获取商品详情")
    public ResponseResult<SpuVO> getDetailById(@PathVariable Long id){
        return ResponseResult.success(this.iSpuService.getDetailById(id));
    }


    @PostMapping("/by/category")
    @ApiOperation("根据分类id分页获取商品信息(包含子分类下的所有商品信息）")
    public ResponseResult<PagingVO<SpuDomain>> getSpuListByCategoryId(@RequestBody CategoryParam categoryParam,
                                                                      @RequestParam(name = "start", defaultValue = "0")
                                                                              Integer start,
                                                                      @RequestParam(name = "count", defaultValue = "8")
                                                                                  Integer count){
         return ResponseResult.success(this.iSpuService.getSpuListByCategoryId(categoryParam.getCategoryIdList(),start,count));
    }

    /**
     * 分页查询商品信息
     * @param
     * @param
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询商品信息")
    public ResponseResult<PagingVO<SpuDomain>> getPages(@RequestParam(name = "start", defaultValue = "0")
                                                         Integer start,
                                             @RequestParam(name = "count", defaultValue = "8")
                                                         Integer count){
        return ResponseResult.success(iSpuService.getPageList(start,count));
    }
}
